package com.blunka.framework.client.db.druid.service;

import java.io.File;
import java.io.FileInputStream;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.apache.log4j.Logger;

import com.blunka.framework.client.db.druid.dbutils.IServiceDbHelper;
import com.blunka.framework.client.db.druid.dbutils.ServerDbHelper;
import com.blunka.framework.client.db.entity.BatchSqlEntity;
import com.blunka.framework.client.ui.entity.BlkTableMetaData;
import com.blunka.framework.client.utils.DesignUtils;


/**
 *
 * @平台：bronca统一开发平台
 * @文件名称：MSSQLServerDbHelper.java
 * @文件描述：druid数据库连接工具mssql
 * @author xuqiang
 * @日期：2017年5月2日上午8:53:25
 *
 */
public class MSSQLServer implements ISQLService{

	private static final Logger logger = Logger.getLogger(MSSQLServer.class);

	/**
	 * 数据库服务类
	 */
	public static IServiceDbHelper serviceDbHelper;

	private static MSSQLServer dbHelper = new MSSQLServer();

	public static MSSQLServer newInstance(){
		return dbHelper;
	}

	private MSSQLServer(){
		try{
			Properties p = new Properties();
			File pfile = new File(DesignUtils.getDir()+"/conf/conf-mssql-db.properties");
			p.load(new FileInputStream(pfile));
			serviceDbHelper = new ServerDbHelper();
			serviceDbHelper.initDataSource(p);
		}catch(Exception e){
			logger.error("数据库连接失败",e);
		}
	}

	/**
	 * 获取业务建模数据版本
	 * @return
	 */
	public String getDBVersion(){
		Map<String,String> versionMap = dbHelper.getDBUtils().getItemMap("SELECT * FROM BLK_TABLE_VERSION");
		return versionMap.get("DB_VERSION");
	}
	/**
	 * 获取数据库操作工具
	 * @return
	 */
	public IServiceDbHelper getDBUtils(){
		return serviceDbHelper;
	}

	@Override
	public String getDBServerIP() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getDBServerName() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void initServerDB() throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<BlkTableMetaData> queryAllNode() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BlkTableMetaData insertNode(BlkTableMetaData node) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BlkTableMetaData insertNodeNoNewId(BlkTableMetaData node) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BatchSqlEntity getinsertNodeNoNewIdSql(BlkTableMetaData node) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BlkTableMetaData updateNode(BlkTableMetaData node) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BlkTableMetaData deleteNode(BlkTableMetaData node) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BlkTableMetaData insertTableNodeModel(BlkTableMetaData node) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BlkTableMetaData insertTableNode(BlkTableMetaData node) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BatchSqlEntity getInsertTableNodeSql(BlkTableMetaData node) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BlkTableMetaData insertTableNodeNoNewId(BlkTableMetaData node) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BlkTableMetaData updateTableNodeModel(BlkTableMetaData node) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BlkTableMetaData updateTableNode(BlkTableMetaData node) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BlkTableMetaData deleteTableNodeModel(BlkTableMetaData node) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BlkTableMetaData deleteTableNode(BlkTableMetaData node) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BlkTableMetaData insertFieldModel(BlkTableMetaData newBlkModel, BlkTableMetaData parentBlkModel)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BlkTableMetaData insertField(BlkTableMetaData newBlkModel, BlkTableMetaData parentBlkModel)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BatchSqlEntity getInsertFieldSql(BlkTableMetaData newBlkModel) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BlkTableMetaData insertField(BlkTableMetaData newBlkModel) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BlkTableMetaData updateFieldModel(BlkTableMetaData newBlkModel, BlkTableMetaData parentBlkModel)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BlkTableMetaData updateField(BlkTableMetaData newBlkModel, BlkTableMetaData parentBlkModel)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BlkTableMetaData deleteFieldModel(BlkTableMetaData newBlkModel, BlkTableMetaData parentBlkModel)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BlkTableMetaData deleteField(BlkTableMetaData newBlkModel, BlkTableMetaData parentBlkModel)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean queryTableOrViewExists(BlkTableMetaData model) throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean queryTableOrViewFieldExists(BlkTableMetaData model, String tablename) throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}
	
	/**
	 * 判断modelname业务模型名称在节点model的子节点中是否存在
	 * @param model
	 * @param modelname
	 * @return
	 * @throws SQLException
	 */
	public boolean queryModelNodeExists(BlkTableMetaData model,String modelname)throws SQLException{
		return false;
	}

	@Override
	public boolean queryIndexExists(String table_fieldindex_name, String tablename) throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void batchModelNode(List<BatchSqlEntity> sqlList) throws Exception {
		// TODO Auto-generated method stub
		
	}



}
